<?php
/**
 * 项目入口文件
 */

//设置错误提示
error_reporting ( E_ALL ^ E_NOTICE );

$__test = 1;
$__updating = 0;

if ($__test) {
	ini_set ( 'display_startup_errors', 1 );
	ini_set ( 'display_errors', 1 );
	if ($__updating) {
		if ($_SERVER ['REMOTE_ADDR'] == '61.51.110.8') {
			/**
			 * 访问网站时认证
			 */
			$cfg ['servers'] ['users'] = array ('gameliumang' => 'gameliumang.com' );
			function authenticate() {
				global $cfg, $_SERVER;
				$password = array_search ( $_SERVER ['PHP_AUTH_PW'], $cfg ['servers'] ['users'] );
				if ($_SERVER ['PHP_AUTH_USER'] != $password || empty ( $password )) {
					header ( 'WWW-Authenticate: Basic realm="Authentication System"' );
					header ( 'HTTP/1.0 401 Unauthorized' );
					include 'update.html';
					exit ();
				}
			}
			authenticate ();
		} else {
			include 'update.html';
			die ();
		}
	}
} else {
	ini_set ( 'display_startup_errors', 0 );
	ini_set ( 'display_errors', 0 );
}

//设置时区
date_default_timezone_set ( 'Asia/Shanghai' );

//公共路径,域名根目录
$_app_path_arr = explode ( DIRECTORY_SEPARATOR, dirname ( __FILE__ ) );
unset ( $_app_path_arr [count ( $_app_path_arr ) - 1] );
unset ( $_app_path_arr [count ( $_app_path_arr ) - 1] );

//定义项目根目录
define ( 'ROOT_DIR', implode ( DIRECTORY_SEPARATOR, $_app_path_arr ) . DIRECTORY_SEPARATOR );

//定义项目控制器分布应用目录
define ( 'APP_ROOT_PATH', ROOT_DIR . 'Application' . DIRECTORY_SEPARATOR );

//定义项目公共配置目录
define ( 'DATA_PATH', ROOT_DIR . 'Data' . DIRECTORY_SEPARATOR );

//定义项目日志存储目录
define ( 'LOG_PATH', ROOT_DIR . 'Logs' . DIRECTORY_SEPARATOR );

//定义项目模型目录
define ( 'MODEL_PATH', ROOT_DIR . 'Model' . DIRECTORY_SEPARATOR );

//定义项目基础库目录
define ( 'LIB_PATH', ROOT_DIR . 'Library' . DIRECTORY_SEPARATOR );

//定义项目数据库目录
define ( 'DB_PATH', ROOT_DIR . 'DB' . DIRECTORY_SEPARATOR );

//设置默认包含路径
set_include_path ( ROOT_DIR . PATH_SEPARATOR . DATA_PATH . PATH_SEPARATOR . LIB_PATH . PATH_SEPARATOR );

//载入项目启动文件
require_once (APP_ROOT_PATH . 'Bootstrap.php');

try {
	$app_bootstrap = new ApplicationBootstrap ( 'api' );
	$app_bootstrap->run ();
} catch ( Zend_Exception $e ) {
	require_once (DATA_PATH . 'errorpage.php');
}
?>